package com.skyline.attraction.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.skyline.attraction.model.AttractionRefrence;
import com.skyline.attraction.type.AttractionRefrenceType;
import com.skyline.base.type.Activity;

public class AttractionRefrenceMapper implements RowMapper<AttractionRefrence> {

	private final static AttractionRefrenceMapper MAPPER = new AttractionRefrenceMapper();

	private static final String COLUMN_ID = "id";
	private static final String COLUMN_ATTRACTIONID = "attractionId";
	private static final String COLUMN_ATTRACTIONNAME = "attractionName";
	private static final String COLUMN_ATTRACTIONPORTRAIT = "attractionPortrait";

	private static final String COLUMN_REFID = "refId";
	private static final String COLUMN_REFRENCEPORTRAIT = "refPortrait";
	private static final String COLUMN_REFRENCETITLE = "refTitle";
	private static final String COLUMN_REFRENCEDIGEST = "refDigest";
	private static final String COLUMN_REFRENCETYPE = "refType";

	private static final String COLUMN_PROVIDERID = "providerId";
	private static final String COLUMN_PROVIDERNICKNAME = "providerNikename";
	private static final String COLUMN_PROVIDEREMAIL = "providerEmail";
	private static final String COLUMN_PROVIDERPORTRAIT = "providerPortrait";

	private static final String COLUMN_CREATETIME = "createTime";
	private static final String COLUMN_UPDATETIME = "updateTime";
	private final static String COLUMN_ACTIVITY = "activity";

	public static AttractionRefrenceMapper getMapper() {
		return MAPPER;
	}

	public AttractionRefrence mapRow(ResultSet rs, int rowNum) throws SQLException {
		AttractionRefrence refrence = new AttractionRefrence();
		refrence.setId(rs.getLong(COLUMN_ID));
		refrence.setAttractionId(rs.getLong(COLUMN_ATTRACTIONID));
		refrence.setAttractionName(rs.getString(COLUMN_ATTRACTIONNAME));
		refrence.setAttractionPortrait(rs.getString(COLUMN_ATTRACTIONPORTRAIT));
		refrence.setRefId(rs.getLong(COLUMN_REFID));
		refrence.setRefPortrait(rs.getString(COLUMN_REFRENCEPORTRAIT));
		refrence.setRefTitle(rs.getString(COLUMN_REFRENCETITLE));
		refrence.setRefDigest(rs.getString(COLUMN_REFRENCEDIGEST));
		refrence.setRefType(AttractionRefrenceType.valueOf(rs.getString(COLUMN_REFRENCETYPE)));
		refrence.setProviderId(rs.getLong(COLUMN_PROVIDERID));
		refrence.setProviderNikename(rs.getString(COLUMN_PROVIDERNICKNAME));
		refrence.setProviderPortrait(rs.getString(COLUMN_PROVIDERPORTRAIT));
		refrence.setProviderEmail(rs.getString(COLUMN_PROVIDEREMAIL));
		refrence.setCreateTime(rs.getDate(COLUMN_CREATETIME));
		refrence.setUpdateTime(rs.getDate(COLUMN_UPDATETIME));
		refrence.setActivity(Activity.valueOf((rs.getString(COLUMN_ACTIVITY))));
		return refrence;
	}
}
